<?php

namespace app\api\controller;

use app\api\model\ShareAccount;
use app\api\model\ShareOrder;
use app\common\controller\Api;

class Crontab extends Api
{
    private ShareOrder $model;

    public function __construct(){
        $this->model = new ShareOrder();
    }
    public function share_order(){
        $res = ShareAccount::all(['result_code'=>'SUCCESS','state'=>2]);
        foreach ($res as $item) {
            $receivers = $item->receivers;
            $arr = json_decode($receivers,true);
            foreach ($arr as &$item1) {
                $item1['order_id'] = $item->order_id;
                $item1['sub_mch_id'] = $item->sub_mch_id;
            }
            $this->model->insertAll($arr);
            ShareAccount::update(['state'=>1],['id'=>$item->id]);
        }
        $this->success("success");
    }
}